package com.gljx.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;


public class GetFnumber {
	

	/**
	 * 获取编码
	 * @param name 功能名称
	 * @return 
	 */
	public static String fnumbers(String name) {
		/*SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		//获取当天
		String time = simpleDateFormat.format(new Date());
		StringBuffer stringBuffer = new StringBuffer();
		String number = null;
		//如果为空说明是第一次,字符串长度小于12
		if(fnumber == null || "".equals(fnumber) || fnumber.length()<12){
			number = "0001";
		}else{
				//取编码最后的12位数
				String fnumberString = fnumber.substring(fnumber.length()-12);
				//取编码时间
				String timeString = fnumberString.substring(0,8);
				//如果是当天就进行+1操作，否则重新生成
				if(timeString.equals(time)){
					//取编码最后的4位数
					String num = fnumberString.substring(fnumberString.length()-4);
					//转成Integer类型
					Integer fnumbers = Integer.valueOf(num);
					//先进行+1操作在转成String
					if(fnumbers < 10){
						if(fnumbers == 9){
							number = "00"+(fnumbers+1); 
						}else{
							 number = "000"+(fnumbers+1); 
						}
					}else if(fnumbers < 100){
						if(fnumbers == 99){
							number = "0"+(fnumbers+1);
						}else{
							number = "00"+(fnumbers+1);
						}
					}else if(fnumbers < 1000){
						if(fnumbers == 999){
							number = ""+(fnumbers+1);
						}else{
							number = "0"+(fnumbers+1);
						}
						  
					}else{
						  number = "0001";
					}
				}else{
					number = "0001";
				}
		}
		//功能名
		stringBuffer.append(name);
		//时间
		stringBuffer.append(time);
		//编码
		stringBuffer.append(number);*/
		//时间格式化到毫秒
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
		StringBuffer stringBuffer = new StringBuffer();
		//生成四位随机数
		//功能名
		stringBuffer.append(name);
		//时间
		stringBuffer.append(simpleDateFormat.format(new Date()));
		//编码
		return stringBuffer.toString();
	}

	/**
	 * 生成四位随机数
	 *
	 * @return
	 */
	public static String random() {
		Random random = new Random();
		String result = "";
		for (int i = 0; i < 2; i++) {
			result += random.nextInt(9);
		}
		return result;
	}

	/*public static void main(String[] args) {
		String aa = fnumbers("WX","wx");
		System.out.println(aa);
	}*/
}
